package com.example.lab_3;




import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.support.v4.app.NavUtils;

public class Lab_3 extends Activity {
	
	public final static String EXTRA_MESSAGE = "Lab_3.rng.MESSAGE";
	private TextView randomNumberDisplay;
	private Intent random_numb_intent;
	Thread  random_number_updater_thread;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lab_3);
        randomNumberDisplay = (TextView) findViewById(R.id.random_number_display);
        this.random_numb_intent = null;
        
        
        random_number_updater_thread = new Thread(new Runnable(){
			@Override
			public void run() {
				if(random_numb_intent != null){
					printRandomNumberDisplay(random_numb_intent.getStringExtra(Lab_3.EXTRA_MESSAGE));
				}
			
			}
    		
    	});
    }

  /*  public void onStart(){
    	random_number_updater_thread.start();
    }
    
    public void onResume(){
    	random_number_updater_thread.start();
    }
    
    
	public void onRestart(){
    	random_number_updater_thread.stop();
    }
    
    public void onStop(){
    	random_number_updater_thread.stop();
    }*/
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_lab_3, menu);
        return true;
    }

 
    public void startRandomNumber(View view) {
    	random_numb_intent = new Intent(this, RandomNumberService.class);
    	//random_number_updater_thread.start();
    	startService(random_numb_intent);
    }
    
    public void stopRandomNumber(View view) {
    	random_numb_intent = new Intent(this, RandomNumberService.class);
    	stopService(random_numb_intent);
    }
    
 /*   final Handler handlerRandomNumber = new Handler() {
        public void handleMessage(Message msg) {
     	  printRandomNumberDisplay( msg.getData().getString("log"));
        }
    };*/
    
    private void printRandomNumberDisplay(String logTex){
 	   if(logTex != ""){
 		  randomNumberDisplay.setText(logTex);
 		   
 	   }
    }
    

}
